package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.qiantu.api.db.LLRoomDBManager;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.glide.GlideApp;

/**
 *    author : Android 轮子哥
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2019/09/22
 *    desc   : 状态数据列表
 */
public final class AddLoadDeviceAdapter extends AppAdapter<DeviceBean> {

    public AddLoadDeviceAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final ImageView iconDevice;
        private final TextView tvDeviceName;
        private final TextView tvFloorRoom;

        private ViewHolder() {
            super(R.layout.item_add_load_device);
            iconDevice = findViewById(R.id.icon_device);
            tvDeviceName = findViewById(R.id.tv_device_name);
            tvFloorRoom = findViewById(R.id.tv_floor_room);
        }

        @Override
        public void onBindView(int position) {
            DeviceBean item = getItem(position);
            tvDeviceName.setText(item.getName());
            tvFloorRoom.setText(LLRoomDBManager.getInstance(getContext()).getFloorRoomName(item.getRoomSerialNo()));
            GlideApp.with(iconDevice).load(item.getOnImageUrl()).into(iconDevice);
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }
}